home *** CD-ROM | disk | FTP | other *** search
/ Discovering Windows 98 / WinExpert9.iso / Tips / VB / State after this tutorial / frmUnits.frm (.txt) next >
Visual Basic Form  |  1997-12-03  |  4KB  |  133 lines

  1. VERSION 5.00
  2. Begin VB.Form frmUnits 
  3.    Caption         =   "Units Conversion"
  4.    ClientHeight    =   1485
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   4065
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   1485
  10.    ScaleWidth      =   4065
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.ComboBox cboConversionTypes 
  13.       Height          =   315
  14.       Left            =   1560
  15.       Style           =   2  'Dropdown List
  16.       TabIndex        =   5
  17.       Top             =   120
  18.       Width           =   2415
  19.    End
  20.    Begin VB.CommandButton cmdConvert 
  21.       Caption         =   "Convert"
  22.       Enabled         =   0   'False
  23.       Height          =   375
  24.       Left            =   2640
  25.       TabIndex        =   4
  26.       Top             =   840
  27.       Width           =   975
  28.    End
  29.    Begin VB.TextBox txtToUnits 
  30.       Enabled         =   0   'False
  31.       Height          =   285
  32.       Left            =   1080
  33.       TabIndex        =   1
  34.       Top             =   1080
  35.       Width           =   855
  36.    End
  37.    Begin VB.TextBox txtFromUnits 
  38.       Height          =   285
  39.       Left            =   1080
  40.       TabIndex        =   0
  41.       Top             =   720
  42.       Width           =   855
  43.    End
  44.    Begin VB.Label Label1 
  45.       Caption         =   "Conversion Type"
  46.       Height          =   255
  47.       Left            =   120
  48.       TabIndex        =   6
  49.       Top             =   120
  50.       Width           =   1335
  51.    End
  52.    Begin VB.Label lblToUnits 
  53.       Caption         =   "<To>"
  54.       Height          =   255
  55.       Left            =   120
  56.       TabIndex        =   3
  57.       Top             =   1080
  58.       Width           =   975
  59.    End
  60.    Begin VB.Label lblFromUnits 
  61.       Caption         =   "<From>"
  62.       Height          =   255
  63.       Left            =   120
  64.       TabIndex        =   2
  65.       Top             =   720
  66.       Width           =   735
  67.    End
  68. Attribute VB_Name = "frmUnits"
  69. Attribute VB_GlobalNameSpace = False
  70. Attribute VB_Creatable = False
  71. Attribute VB_PredeclaredId = True
  72. Attribute VB_Exposed = False
  73. Option Explicit
  74. Private mastrFromUnitNames(0 To 3) As String
  75. Private mastrToUnitNames(0 To 3) As String
  76. Private masngMultiplicationFactors(0 To 3) As Single
  77. Private msngChosenFactor As Single
  78. Private Sub cboConversionTypes_Click()
  79.     Dim intIndex As Integer
  80.     intIndex = cboConversionTypes.ListIndex
  81.         
  82.     lblFromUnits = mastrFromUnitNames(intIndex)
  83.     txtFromUnits = ""
  84.     lblToUnits = mastrToUnitNames(intIndex)
  85.     txtToUnits = ""
  86.         
  87.     msngChosenFactor = masngMultiplicationFactors(intIndex)
  88. End Sub
  89. Private Sub cmdConvert_Click()
  90.     txtToUnits = CStr(CSng(txtFromUnits) * msngChosenFactor)
  91. End Sub
  92. Private Sub Form_Load()
  93.     Dim intIndex As Integer
  94.         
  95.     masngMultiplicationFactors(0) = 1.6093
  96.     mastrFromUnitNames(0) = "Miles"
  97.     mastrToUnitNames(0) = "Kilometres"
  98.         
  99.     masngMultiplicationFactors(1) = 0.9144
  100.     mastrFromUnitNames(1) = "Yards"
  101.     mastrToUnitNames(1) = "Metres"
  102.         
  103.     masngMultiplicationFactors(2) = 0.3048
  104.     mastrFromUnitNames(2) = "Feet"
  105.     mastrToUnitNames(2) = "Metres"
  106.         
  107.     masngMultiplicationFactors(3) = 2.52
  108.     mastrFromUnitNames(3) = "Inches"
  109.     mastrToUnitNames(3) = "Centimetres"
  110.         
  111.     For intIndex = 0 To 3
  112.         cboConversionTypes.AddItem mastrFromUnitNames(intIndex) & " to " & mastrToUnitNames(intIndex)
  113.     Next
  114.         
  115.     'Pre-select list item number 0
  116.     cboConversionTypes.ListIndex = 0
  117. End Sub
  118. Private Sub txtFromUnits_Change()
  119.     If txtFromUnits.Text = "" Then
  120.        cmdConvert.Enabled = False
  121.     Else
  122.        cmdConvert.Enabled = True
  123.     End If
  124. End Sub
  125. Private Sub txtFromUnits_KeyPress(KeyAscii As Integer)
  126.     If Not IsNumeric(Chr(KeyAscii)) Then
  127.         If KeyAscii <> 8 Then
  128.             KeyAscii = 0
  129.             Beep
  130.         End If
  131.     End If
  132. End Sub
  133.